package structural.flyweight;

import java.util.HashMap;
import java.util.Map;

public class FlyweightFactory {

    private static Map<String,Flyweight> pool = new HashMap<>();

    public static Flyweight getInstance(String type){
        Flyweight original =  pool.putIfAbsent(type, new Flyweight(type));
        if(original == null) System.out.println("新创建对象并加入pool, type="+type);
        return pool.get(type);
    }
}
